<?php
class TreeNode {
    public $val = null;
    public $left = null;
    public $right = null;
    function __construct($value) {
        $this->val = $value;
    }
}

class Solution {

    /**
     * @param TreeNode $root
     * @param Integer $val
     * @return TreeNode
     */
    function searchBST($root, $val) {
        if ($root == null) {
            return null;
        }
        if ($root->val == $val) {
            return $root;
        }
        if ($val > $root->val) {
            return $this->searchBST($root->right, $val);
        }
        if ($val < $root->val) {
            return $this->searchBST($root->left, $val);
        }
        return null;
    }
}